package cn.ryh.designpatterndemo.singletonpattern;

/**
 * 饿汉式单例
 */
public class HungrySingleton {
    /**
     * 私有构造函数，防止在其他地方备实例化
     */
    private HungrySingleton() {
    }

    /**
     * 使用静态内部类来维护单例
     */
    private static class inner {
        private final static HungrySingleton ourInstance = new HungrySingleton();
    }

    /**
     * 获取实例
     *
     * @return
     */
    public static HungrySingleton getInstance() {

        return inner.ourInstance;
    }
}